package com.ggh.jinjilive.dialog.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.amap.api.services.core.PoiItem;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemNearMessageBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;

import java.util.List;


public class NearMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<PoiItem> poiItemList;
    public void setPoiItemList(List<PoiItem> poiItemList){
        this.poiItemList = poiItemList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemNearMessageBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_near_message, parent, false);
        return new ItemViewHolder(binding);
    }



    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder recyclerViewholder, int position) {
        ItemViewHolder holder = (ItemViewHolder) recyclerViewholder;
        PoiItem poiItem = poiItemList.get(position);
        if(null != poiItem){
            //标题
            holder.binding.tvTitle.setText(poiItem.getTitle());
            //内容
            holder.binding.tvContent.setText(poiItem.getSnippet());
            //点击
            holder.binding.llLocation.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(null != addItemOnClickListener){
                        addItemOnClickListener.onSkipClicked(position,poiItem);
                    }
                }
            });
        }
    }



    @Override
    public int getItemCount() {
        return null == poiItemList ? 0 : poiItemList.size();
    }


    public class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemNearMessageBinding binding;

        public ItemViewHolder(@NonNull ItemNearMessageBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }


    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener){
        this.addItemOnClickListener = addItemOnClickListener;
    }


}
